#include <bits/stdc++.h>
#include <limits>
#include <unordered_map>

using namespace std;

class Solution {
    using ll = long long;

public:
    long long minimumTime(vector<int>& time, int totalTrips)
    {
	unordered_map<int, int> freq;
	for (int t : time) freq[t]++;
	ll lo = 1, hi = numeric_limits<long long>::max();
	while (lo < hi) {
	    ll mid = lo + (hi - lo) / 2, temp = 0;
	    for (auto [ti, fr] : freq) {
		if (mid / ti >= totalTrips) temp = totalTrips + 1;
		temp += fr * (mid / ti);
		if (temp >= totalTrips) break;
	    }
	    if (temp >= totalTrips) hi = mid;
	    else lo = mid + 1;
	}
	return lo;
    }

private:
};

int main()
{
    [[maybe_unused]] Solution solution;
    return 0;
}
